home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / bbxymod.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-12-07  |  5.1 KB  |  152 lines

  1. (*===========================================================================*)
  2. (* X/Ymodem Protocol processor -- Main line                                  *)
  3. (*                                                                           *)
  4. (*   Copyright 1989 by H. Roy Engehausen.  All rights reserved.              *)
  5. (*                                                                           *)
  6. (*===========================================================================*)
  7.  
  8. PROCEDURE xy_xfer;
  9.  
  10.   CONST
  11.     nul       = #0;
  12.     soh       = #1;
  13.     stx       = #2;
  14.     etx       = #3;
  15.     eot       = #4;
  16.     enq       = #5;
  17.     ack       = #6;
  18.     dle       = #16;
  19.     nak       = #21;
  20.     can       = #24;
  21.     eof       = #26;
  22.  
  23.     small_buff_size = 10;
  24.  
  25.   TYPE
  26.     buff_tail = RECORD
  27.                   CASE BYTE OF
  28.                     0: (xy_chksum : BYTE);
  29.                     1: (xy_crc_hi : BYTE;
  30.                         xy_crc_lo : BYTE);
  31.                   END;
  32.  
  33.     buff_type = RECORD
  34.                   xy_type        : CHAR;
  35.                   xy_b_no        : BYTE;
  36.                   xy_b_no_invert : BYTE;
  37.                   CASE BYTE OF
  38.                     0: (x_b    : ARRAY[1..128] OF CHAR;
  39.                         x_tail : buff_tail);
  40.                     1: (y_b    : ARRAY[1..1024] OF CHAR;
  41.                         y_tail : buff_tail);
  42.                 END;
  43.  
  44.     buff_ptr  = ^buff_type;
  45.  
  46.   VAR
  47.     b_size       : WORD;
  48.     batch_sw     : BOOLEAN;
  49.     big_buff     : buff_ptr;
  50.     block_no     : BYTE;
  51.     block_type   : CHAR;
  52.     check_num    : WORD;
  53.     crc_sw       : BOOLEAN;
  54.     curr_size    : LONGINT;
  55.     data_file    : ^FILE;
  56.     error_cnt    : BYTE;
  57.     first_sw     : BOOLEAN;
  58.     file_size    : LONGINT;
  59.     header_str   : STRING[128];
  60.     small_buff   : buff_ptr;
  61.     tail_ptr     : ^buff_tail;
  62.     time_to_wait : WORD;
  63.     to_sw        : BOOLEAN;
  64.     ymodem_sw    : BOOLEAN;
  65.  
  66.   {$I BBXYMODC.PAS}
  67.   {$I BBXYMODU.PAS}
  68.   {$I BBXYMODD.PAS}
  69.  
  70.   BEGIN;
  71.  
  72.     (*-----------------------------------------------------------------------*)
  73.     (* Locate the file area                                                  *)
  74.     (*-----------------------------------------------------------------------*)
  75.  
  76.     data_file := @active_tcb^.io_fe^.fe_bin;
  77.  
  78.     (*-----------------------------------------------------------------------*)
  79.     (* Ready the data file                                                   *)
  80.     (*-----------------------------------------------------------------------*)
  81.  
  82.     assign(data_file^, pkfname);
  83.  
  84.     (*-----------------------------------------------------------------------*)
  85.     (* Get the buffer area                                                   *)
  86.     (*-----------------------------------------------------------------------*)
  87.  
  88.     big_buff   := get_task_mem('BIN', SIZEOF(buff_type));
  89.  
  90.     small_buff := get_task_mem('BIN', small_buff_size);
  91.  
  92.     (*-----------------------------------------------------------------------*)
  93.     (* Ready things                                                          *)
  94.     (*-----------------------------------------------------------------------*)
  95.  
  96.     crc_sw       := bin_xfer <> bin_xmodem;
  97.     batch_sw     := bin_xfer = bin_ymodem_batch;
  98.     ymodem_sw    := (bin_xfer = bin_ymodem_batch) OR (bin_xfer = bin_ymodem);
  99.  
  100.     curr_size    := 0;
  101.  
  102.     IF active_port^.port_type <> port_modem THEN
  103.       time_to_wait := active_port^.time_out
  104.     ELSE
  105.       time_to_wait := 10;
  106.  
  107.     (*-----------------------------------------------------------------------*)
  108.     (* Do the transfer                                                       *)
  109.     (*-----------------------------------------------------------------------*)
  110.  
  111.     set_binary_switch(TRUE);
  112.  
  113.     IF up_it THEN
  114.       xy_upload
  115.     ELSE
  116.       xy_download(FALSE);
  117.  
  118.     (*-----------------------------------------------------------------------*)
  119.     (* Close the file                                                        *)
  120.     (*-----------------------------------------------------------------------*)
  121.  
  122.     get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
  123.     {$I-}
  124.     CLOSE(data_file^);
  125.     b_size := IORESULT;
  126.     {$I+}
  127.     free_semaphore(semaphore_interrupts);
  128.  
  129.     (*-----------------------------------------------------------------------*)
  130.     (* Do batch ending data                                                  *)
  131.     (*-----------------------------------------------------------------------*)
  132.  
  133.     IF batch_sw THEN
  134.       IF up_it THEN
  135.         get_a_block
  136.       ELSE
  137.         xy_download(TRUE);
  138.  
  139.     (*-----------------------------------------------------------------------*)
  140.     (* Clear the binary switch                                               *)
  141.     (*-----------------------------------------------------------------------*)
  142.  
  143.     set_binary_switch(FALSE);
  144.  
  145.     (*-----------------------------------------------------------------------*)
  146.     (* Free the buffer area                                                  *)
  147.     (*-----------------------------------------------------------------------*)
  148.  
  149.     free_task_mem('BIN', TRUE);
  150.  
  151.   END;
  152.